<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>登陆页面</title>
	<%@ include file="/common/meta.jsp"%>
	<%@ include file="/common/common.jsp"%>
	<!--[if IE 6]>
	<script type="text/javascript" src="js/DD_belatedPNG.js" ></script>
	
	<script type="text/javascript">
	DD_belatedPNG.fix('*');
	</script>
	<![endif]-->
</head>
<!-- login edited by huanglijun 2011-04-27 -->
<body class="ad-bg">
	<div class="ad-main">
		<div class="ad-left">集“内容发布、用户管理、站群建设”于一体；协助各类
网站向“服务化、系统化、协同工作”的特点发展。<br/><span>灰兔子CMS，做最好的网站管理系统！</span></div>
		<div class="ad-right">
			<form method="post" action="${ctx}/login-logon.action" id="loginform" onsubmit="return chkForm();" >
				<div class="ad-tipbox ov"    id="tipbox"><s:actionerror></s:actionerror></div>  
				<div class="ad-usernametext">用户名：</div>
				<div class="ad-usernameinput"><input id="loginName" type="text" maxlength="32" name="adminBean.loginName" /></div>
				<div class="ad-passwordtext">密码：</div>
				<div class="ad-passwordinput"><input id="password" type="password" maxlength="32" name="adminBean.passwd" /></div>
				<div id='authority' style='display:none'> 
					<div class="ad-codetext">验证码：</div>
					<div class="ad-codeinput"><input type="text" maxlength="6" name="adminBean.authCode" id="authCode" /></div>
					<div class="ad-codeimg"><img src="${ctx}/login-authcode.action" id="authCodeImg" /></div>
					<div class="ad-codenext"><span>点图片换一张</span></div>
					<input type="hidden" id="authCodeImgMark" value="no"/>
				</div>
				<div class="clear"></div>
				<div class="ad-autologin"> 
					<input type="checkbox" id="autologin" /><label for="autologin" id="autologinbg">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;记住我</label>
				</div>
				<!-- <div class="ad-submit"><a href='#' class='loginbtn'  id="mousetype">确定</a></div> --> 
				<div class="ad-submit"><input type="submit" class='loginbtn' value="确定"></input></div>
			</form>
		</div>
		<div class="ad-bottom">灰兔子内容管理系统 copyright 2002-2011 All Rights Reserved<br/>建议使用1024*768分辨率，IE6.0以上浏览器版本</div>
	</div>
</body> 
<script src="${ctx}/js/jquery.cookie.js" type="text/javascript"></script>
<script type="text/javascript">
/*自动登录复选框样式切换 edited by huanglijun 2011-04-27*/
var autologinbg=document.getElementById("autologinbg");
autologinbg.onclick=function(){
	if(this.className!="selected")
	{
		this.className="selected";
	}
	else
	{
		this.className="";
	}
}
/*输入框聚焦样式切换 edited by huanglijun 2011-04-27*/
var loginform=document.getElementById("loginform");
var inputfocus=loginform.getElementsByTagName("input");
for(var i=0;i<3;i++)
{
	inputfocus[i].onfocus=function(){
		this.className="focus";
		//tipbox.style.display="none";
	}
	inputfocus[i].onblur=function(){
		this.className="";
	}
}
/*用户登录输错提示 edited by huanglijun 2011-04-27*/
var tipbox=document.getElementById("tipbox");
tipbox.style.display="none";
function check(){
	if ($("#loginName").val()=='' || $.trim($("#loginName").val())==''){
		tipbox.style.display="";
		tipbox.innerHTML="请输入用户名";
		$("#loginName").focus();
		return false;
	}
	if ($("#password").val()=='' || $.trim($("#password").val())==''){
		tipbox.style.display="";
		tipbox.innerHTML="请输入密码";
		$("#password").focus();
		return false;
	}
	//记下Cookie
	if($("#autologin").attr("checked")){
		 var date = new Date();
         date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000));//设置30天
		 $.cookie("grayrabbit_cms_login_name", $('#loginName').val(), { path: '/', expires: date ,secure: false});
		 $.cookie("grayrabbit_cms_login_password", $('#password').val(), { path: '/', expires: date ,secure: false});
	}
	//清除cookie,没选中
	else{
		 $.cookie("grayrabbit_cms_login_name", null, { path: '/' });
		 $.cookie("grayrabbit_cms_login_password", null, { path: '/' });
	}
	return true;
} 
function chkForm(){
	return check();
} 
$(function(){
	var errorMessage = $("#tipbox").html();
	if(errorMessage=="" || errorMessage==null){
		$("#tipbox").attr("style","display:none");
	}else{
		$("#tipbox").attr("style","");
	}
});
/* function loginFormSubmit(){  
 	$.ajax({	
		url:"${ctx}/login-logon.action?time="+new Date().getTime(),
		data:{"adminBean.loginName":$("#loginName").val(),
			  "adminBean.passwd":$("#password").val(),
			  "adminBean.authCode":$("#authCode").val()},
		dataType:"text",
		type:"get",
		success:function(data){
			try {
				var json = eval('('+data+')');
				if(json.flag){
					// $.cookie("grayrabbit_cms_login_name", $('#loginName').val(), { expires: 365, path: '/', secure: false });
					document.location.href='${ctx}/go.action'; 
				}else{
					$('#authCodeImg').attr('src', '${ctx}/login-authcode.action?r=' + new Date().getTime());
					tipbox.style.display="";
					tipbox.innerHTML=json.msg;
					if(json.authFlag){
						authority();
					}
				}				
			} catch (e) {
				 alert('\u767b\u9646\u5f02\u5e38');
			}
		}
	}); 
} */
function authority(){
	var authDiv=document.getElementById("authority"); 
	authDiv.style.display="block"; 
	$("#authCode").val('');
}
$(function(){
	<s:if test="hasActionErrors()">
	//登录出现异常
	 $.cookie("grayrabbit_cms_login_name", null, { path: '/' });
	 $.cookie("grayrabbit_cms_login_password", null, { path: '/' });
	</s:if>
	session_logout();
	/*  $("#mousetype").click(function(){		
		   if(check()){
		   		loginFormSubmit();   
		   } 
	 }); */
	$('#authCodeImg').click(function() { 
			$('#authCodeImg').attr('src', '${ctx}/login-authcode.action?r=' + new Date().getTime());
	});
	var username = $.cookie('grayrabbit_cms_login_name'); 
	if(username!=null&&username!='') {
		$('#loginName').val(username);
		var pd = $.cookie('grayrabbit_cms_login_password');
		if(pd!=null&&pd!=''){
			$('#password').val(pd);
			$("#autologin").attr("checked",true);
			autologinbg.className="selected";//选中
		}
		else{
			autologinbg.className="";
		}
		showAuthCode();		
	} 
	//用户名null，不选中
	else{
		autologinbg.className="";
	}
	
	$("#loginName").blur(function(){
		showAuthCode();  
	});
});
$("input").each(function(i,item){
	$(item).keyup(function(event){
		event = event || window.event; 
		if(event.keyCode==13){
			if(check()){
				$(loginform).submit();
		   } 
		} 
	});
}); 
function showAuthCode(){ 
	var name =$("#loginName").val();
	if(!name || name=='') return;	
	var mark = $("#authCodeImgMark").val();	 
	if(mark  && mark=='ok'){
		 $("#authority").attr("style","display:block");
		 $("#authCodeImgMark").val('no');
		 return ;
	}else{
		$.ajax({
			url:"${ctx}/login-authcheck.action?time="+new Date().getTime(),
			dataType:"text",
			type:"post",
			data:{"adminBean.loginName":$.trim(name)},
			success:function(data){
				var json = eval('('+data+')');
				if(json.flag){
					 $("#authority").attr("style","display:block");
					 $("#authCodeImgMark").val('ok');	
				}else{
					 $("#authority").attr("style","display:none");
					 $("#authCodeImgMark").val('no');	
				}
			}
		});
	}
}
function session_logout(){
    var win = window; 
	if(win!=win.parent){
		top.location.href="${ctx}/login.action";
	}
}
</script>
</html>
